package aimis.repo;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import aimis.domain.Authority;

import java.util.Set;

public interface AuthorityRepo extends JpaRepository<Authority, Long> {
    @Query("""
            select authority from Authority as authority where
             :name is null or authority.name like %:name%
            """)
    Page<Authority> findByQuery(String name, Pageable pageable);

    Authority findByName(String name);

    @Query("""
            select authority from Authority as authority where
             :name is null or authority.name like %:name%
            """)
    Set<Authority> findByNameLike(String name);

}
